<?php
/**
 * Created by Chongyi
 * Date: 2015/10/10 0010
 * Time: 下午 2:48
 */

// 后台路由
Route::group(['prefix' => 'admin', 'namespace' => 'Admin', 'middleware' => 'admin.auth'], function () {

    Route::get('private/image/{id}', [
        'as' => 'private.admin.image',
        function ($id) {
            try {
                $file = \App\B2BProject\AttachmentPrivateFiles::findOrFail($id);
                header('Content-Type: ' . $file->mime_type);
                $file->readToBuffer();
            } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
                return response('Not found', 404);
            }
        }
    ]);

    Route::controller('access', 'AuthController', ['getLogin' => 'admin.login', 'getLogout' => 'admin.logout']);

    // 设置站点设置
    Route::resource('site-setting', 'Setting\SiteSettingController',
        [
            'names' => [
                'index'   => 'admin.site-setting.index',
                'create'  => 'admin.site-setting.create',
                'update'  => 'admin.site-setting.update',
                'edit'    => 'admin.site-setting.edit',
                'destroy' => 'admin.site-setting.destroy',
            ]
        ]);

    // 商品分类
    Route::get('goods-category',
        [
            'uses' => 'Goods\CategoryController@child',
            'as'   => 'admin.goods.category.child',
        ]);

    Route::get('goods-category/parent',
        [
            'uses' => 'Goods\CategoryController@parent',
            'as'   => 'admin.goods.category.parent',
        ]);

    Route::resource('goods-category', 'Goods\CategoryController',
        [
            'names' => [
                'index'   => 'admin.goods.category',
                'create'  => 'admin.goods.category.create',
                'update'  => 'admin.goods.category.update',
                'edit'    => 'admin.goods.category.edit',
                'destroy' => 'admin.goods.category.destroy',
            ],
        ]);
    //account 账户设置
    Route::resource('account', 'Account\AccountManagementController',
        [
            'names' => [
                'index'   => 'admin.account.index',
                'create'  => 'admin.account.create',
                'update'  => 'admin.account.update',
                'edit'    => 'admin.account.edit',
                'destroy' => 'admin.account.destroy',
            ],
        ]);


    //商品批量
    //TODO 需要修改put -- delete
    Route::put('goods/batch-remove',
        [
            'uses' => 'Goods\GoodsController@batchRemove',
            'as'   => 'admin.goods.manage.batch-remove',
        ]);
    //批量下架
    Route::put('goods/un-shelve',
        [
            'uses' => 'Goods\GoodsController@unShelve',
            'as'   => 'admin.goods.manage.un-shelve',
        ]);
    //批量上架
    Route::put('goods/shelve',
        [
            'uses' => 'Goods\GoodsController@shelve',
            'as'   => 'admin.goods.manage.shelve',
        ]);

    // 商品管理
    Route::resource('goods', 'Goods\GoodsController',
        [
            'names' => [
                'index'  => 'admin.goods.manage.index',
                'edit'   => 'admin.goods.manage.edit',
                'update' => 'admin.goods.manage.update',
            ],
        ]);


    // 品牌
    Route::delete('goods-brand',
        [
            'uses' => 'Goods\BrandsController@batchRemove',
            'as'   => 'admin.goods.brand.batch-remove',
        ]);

    Route::resource('goods-brand', 'Goods\BrandsController',
        [
            'names' => [
                'index'   => 'admin.goods.brand.index',
                'create'  => 'admin.goods.brand.create',
                'update'  => 'admin.goods.brand.update',
                'edit'    => 'admin.goods.brand.edit',
                'destroy' => 'admin.goods.brand.destroy',
            ],
        ]
    );

    // 交易--供求信息

    //供应商
    Route::put('trade-provider',
        [
            'uses' => 'Trade\ProviderInfoController@batchRemove',
            'as'   => 'admin.trade.provider.batch-remove',
        ]);

    Route::resource('trade-provider', 'Trade\ProviderInfoController',
        [
            'names' => [
                'index'   => 'admin.trade.provider.index',
                'create'  => 'admin.trade.provider.create',
                'update'  => 'admin.trade.provider.update',
                'edit'    => 'admin.trade.provider.edit',
                'destroy' => 'admin.trade.provider.destroy',
            ],
        ]
    );
    //采购商
    Route::put('trade-purchaser',
        [
            'uses' => 'Trade\PurchaserInfoController@batchRemoveBuyer',
            'as'   => 'admin.trade.purchaser.batch-remove-buyer',
        ]);

    Route::resource('trade-purchaser', 'Trade\PurchaserInfoController',
        [
            'names' => [
                'index'   => 'admin.trade.purchaser.index',
                'create'  => 'admin.trade.purchaser.create',
                'update'  => 'admin.trade.purchaser.update',
                'edit'    => 'admin.trade.purchaser.edit',
                'destroy' => 'admin.trade.purchaser.destroy',
            ],
        ]
    );

    Route::resource('trade-leads', 'Trade\TradeLeadsController',
        [
            'names' => [
                'index' => 'admin.trade.leads.index',
            ],
        ]
    );

    // 交易--订单信息
    Route::resource('trade-order', 'Trade\OrderController',
        [
            'names' => [
                'index'   => 'admin.trade.order.index',
                'create'  => 'admin.trade.order.create',
                'update'  => 'admin.trade.order.update',
                'edit'    => 'admin.trade.order.edit',
                'destroy' => 'admin.trade.order.destroy',
            ],
        ]
    );
    //运营--物流管理
    Route::resource('logistics', 'Manage\LogisticsPriceController',
        [
            'names' => [
                'index'   => 'admin.logistics.index',
                'create'  => 'admin.logistics.create',
                'update'  => 'admin.logistics.update',
                'edit'    => 'admin.logistics.edit',
                'destroy' => 'admin.logistics.destroy',
            ],
        ]
    );

    // TODO cms模块
    Route::resource('article', 'Site\ArticleController', [
        'names' => [
            'index'   => 'admin.article.index',
            'create'  => 'admin.article.create',
            'update'  => 'admin.article.update',
            'edit'    => 'admin.article.edit',
            'destroy' => 'admin.article.destroy',
        ],
    ]);

    //site --热点词
    Route::get('hot-word/position',
        [
            'uses' => 'Site\HotWordController@getPosition',
            'as'   => 'admin.hot.word.position',
        ]);
    //批量删除
    Route::delete('hot-word',
        [
            'uses' => 'Site\HotWordController@batchRemove',
            'as'   => 'admin.hot.word.batch-remove',
        ]);


    Route::resource('hot-word', 'Site\HotWordController', [
        'names' => [
            'index'   => 'admin.hot.word.index',
            'create'  => 'admin.hot.word.create',
            'update'  => 'admin.hot.word.update',
            'edit'    => 'admin.hot.word.edit',
            'destroy' => 'admin.hot.word.destroy',
        ],
    ]);

    //推荐位--商家

    //批量删除
    Route::delete('recommend-merchant',
        [
            'uses' => 'Site\Recommend\MerchantController@batchRemove',
            'as'   => 'admin.merchant.batch-remove',
        ]);

    Route::resource('recommend-merchant', 'Site\Recommend\MerchantController', [
        'names' => [
            'index'   => 'admin.merchant.index',
            'create'  => 'admin.merchant.create',
            'update'  => 'admin.merchant.update',
            'edit'    => 'admin.merchant.edit',
            'destroy' => 'admin.merchant.destroy',
        ],
    ]);

    //推荐位--物流公司

    //批量删除
    Route::delete('recommend-logistics',
        [
            'uses' => 'Site\Recommend\LogisticsController@batchRemove',
            'as'   => 'admin.logistics.batch-remove',
        ]);

    Route::resource('recommend-logistics', 'Site\Recommend\LogisticsController', [
        'names' => [
            'index'   => 'admin.logistics.index',
            'create'  => 'admin.logistics.create',
            'update'  => 'admin.logistics.update',
            'edit'    => 'admin.logistics.edit',
            'destroy' => 'admin.logistics.destroy',
        ],
    ]);

    // 供应商
    // 审核
    Route::put('provider-details/{id}/pass',
        [
            'uses' => 'Member\Provider\ProviderController@audit',
            'as'   => 'admin.provider.audit',
        ]);

    Route::put('provider-details/{id}/refuse',
        [
            'uses' => 'Member\Provider\ProviderController@refuse',
            'as'   => 'admin.provider.refuse',
        ]);

    Route::get('provider-details/{id}',
        [
            'uses' => 'Member\Provider\ProviderController@authDetails',
            'as'   => 'admin.provider.auth-details',
        ]);
    // 批量删除
    Route::delete('provider',
        [
            'uses' => 'Member\Provider\ProviderController@batchRemove',
            'as'   => 'admin.provider.batch-remove',
        ]);

    Route::resource('provider', 'Member\Provider\ProviderController', [
        'names' => [
            'index'   => 'admin.provider.index',
            'create'  => 'admin.provider.create',
            'update'  => 'admin.provider.update',
            'edit'    => 'admin.provider.edit',
            'destroy' => 'admin.provider.destroy',
        ],
    ]);

    // 采购商

    // 批量删除
    Route::delete('purchaser',
        [
            'uses' => 'Member\Purchaser\PurchaserController@batchRemove',
            'as'   => 'admin.purchaser.batch-remove',
        ]);

    Route::resource('purchaser', 'Member\Purchaser\PurchaserController', [
        'names' => [
            'index'   => 'admin.purchaser.index',
            'create'  => 'admin.purchaser.create',
            'update'  => 'admin.purchaser.update',
            'edit'    => 'admin.purchaser.edit',
            'destroy' => 'admin.purchaser.destroy',
        ],
    ]);
    Route::resource('category', 'Site\CategoryController',
        [
            'names' => [
                'index'   => 'admin.category.index',
                'create'  => 'admin.category.create',
                'destroy' => 'admin.category.destroy',
                'edit'    => 'admin.category.edit',
                'update'  => 'admin.category.update',
            ],
        ]);
    // 会员
    Route::resource('member', 'Member\MemberController', [
        'names' => [
            'index'   => 'admin.member.index',
            'create'  => 'admin.member.create',
            'destroy' => 'admin.member.destroy',
            'edit'    => 'admin.member.edit',
            'update'  => 'admin.member.update',
        ],
    ]);

    //物流询价管理
    Route::resource('logistics', 'Manage\LogisticsPriceController', [
        'names' => [
            'index'   => 'admin.logistics.enquiry.index',
            'create'  => 'admin.logistics.enquiry.create',
            'update'  => 'admin.logistics.enquiry.update',
            'edit'    => 'admin.logistics.enquiry.edit',
            'destroy' => 'admin.logistics.enquiry.destroy',
        ],
    ]);

    // 管理员
    Route::delete('admin', ['uses' => 'Authorization\AdminController@batchRemove', 'as' => 'admin.admin.batch-remove']);
    Route::resource('admin', 'Authorization\AdminController', [
        'names' => [
            'index'   => 'admin.admin.index',
            'create'  => 'admin.admin.create',
            'edit'    => 'admin.admin.edit',
            'update'  => 'admin.admin.update',
            'destroy' => 'admin.admin.destroy',
        ],
    ]);

    Route::get('role/selector', [
        'as'   => 'admin.role.selector',
        'uses' => function () {
            $collection = \App\B2BProject\Admin\Authority\Rbac\Role::orderBy('created_at', 'desc')->get();

            $data = [];

            foreach ($collection as $role) {
                $data[] = ['code' => $role->id, 'text' => $role->display_name];
            }

            return response()->json(['data' => $data]);
        }
    ]);

    // 管理员角色
    Route::delete('role',
        ['uses' => 'Authorization\AdminRoleController@batchRemove', 'as' => 'admin.role.batch-remove']);
    Route::resource('role', 'Authorization\AdminRoleController', [
        'names' => [
            'index'   => 'admin.role.index',
            'create'  => 'admin.role.create',
            'edit'    => 'admin.role.edit',
            'destroy' => 'admin.role.destroy',
            'update'  => 'admin.role.update',
        ],
    ]);

    Route::resource('permission', 'Authorization\PermissionController', [
        'names' => [
            'index' => 'admin.permission.index',
        ],
    ]);

    Route::resource('role.permission', 'Authorization\RolePermissionController', [
        'names' => [
            'index' => 'admin.role-permission.index',
        ],
    ]);


    Route::controller('upload', 'UploadController');
    Route::controller('/', 'Dashboard\DashboardController', ['getIndex' => 'admin.dashboard']);
});
